package xyz.xuminghai.javafx_learn.animation.transition;

import javafx.animation.*;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.layout.BorderPane;
import javafx.scene.paint.Color;
import javafx.scene.shape.Rectangle;
import javafx.stage.Stage;
import javafx.util.Duration;

/**
 * 2023/7/21 22:14 星期五<br/>
 * 此Transition并行播放一系列Animations 。
 *
 * @author xuMingHai
 */
public class ParallelTransitionApp extends Application {

    private final BorderPane root = new BorderPane();

    public static void main(String[] args) {
        Application.launch(args);
    }

    @Override
    public void init() {
        Rectangle rectangle = new Rectangle(100.0, 100.0);

        Duration duration = Duration.millis(3000.0);

        FillTransition fillTransition = new FillTransition(duration,
                rectangle, null, Color.BLUE);

        ScaleTransition scaleTransition = new ScaleTransition(duration, rectangle);
        scaleTransition.setByX(1.0);
        scaleTransition.setByY(1.0);

        StrokeTransition strokeTransition = new StrokeTransition(duration, rectangle,
                Color.BLACK, Color.RED);

        ParallelTransition parallelTransition = new ParallelTransition(rectangle,
                fillTransition, scaleTransition,
                strokeTransition);

        parallelTransition.setCycleCount(Animation.INDEFINITE);
        parallelTransition.setAutoReverse(true);
        parallelTransition.play();


        root.setCenter(rectangle);
    }


    public void start(Stage primaryStage) {
        primaryStage.setTitle(getClass().getSimpleName());
        Scene scene = new Scene(root, 800, 600);
        primaryStage.setScene(scene);
        primaryStage.show();
    }

}
